package com.cinemahorairerapido.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cinemahorairerapido.R;
import com.cinemahorairerapido.bean.Cinema;

public class FavoriteCinemaAdapter extends BaseAdapter {

	List<Cinema> cinemaList = new ArrayList<Cinema>();

	Context context;

	LayoutInflater inflater;

	private class ViewHolder {
		TextView nameTextView;
		TextView addressTextView;
	}

	public FavoriteCinemaAdapter(List<Cinema> pCinemaList, Context context) {
		super();
		this.cinemaList = pCinemaList;
		this.context = context;

		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return cinemaList.size();
	}

	@Override
	public Object getItem(int position) {
		return cinemaList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return cinemaList.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = inflater.inflate(R.layout.favoritecinemarow, null);

			holder.nameTextView = (TextView) convertView.findViewById(R.id.nameFavoriteRow);
			holder.addressTextView = (TextView) convertView.findViewById(R.id.addressFavoriteRow);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		final Cinema cinema = cinemaList.get(position);

		holder.nameTextView.setText(cinema.getName());
		holder.addressTextView.setText(cinema.getAddress() + " " + cinema.getPostalCode() + " " + cinema.getCity());

		return convertView;
	}

}